<template>
  <div class='container' >
    <el-dialog width="900px" title="题目预览" :visible="showDialog" @close="close">
      <el-form ref="clearData" :model="dataList">
        <el-row :gutter="20">
        <el-col :span="6"><div class="grid-content bg-purple">【题型】:{{dataList.questionType === '1' ? '单选' : dataList.questionType === '2' ? '多选' : '简答题'}}</div></el-col>
        <el-col :span="6"><div class="grid-content bg-purple">【难度】:{{ dataList.difficulty === '1' ? '简单' : dataList.difficulty === '2' ? '一般' : '困难' }}</div></el-col>
        <el-col :span="6"><div class="grid-content bg-purple">【编号】:{{dataList.id}}</div></el-col>
        <el-col :span="6"><div class="grid-content bg-purple">【标签】:{{dataList.tags}}</div></el-col>
        <el-col :span="6"><div class="grid-content bg-purple">【学科】:{{dataList.subjectName}}</div></el-col>
        <el-col :span="6"><div class="grid-content bg-purple">【目录】:{{dataList.directoryName}}</div></el-col>
        <el-col :span="6"><div class="grid-content bg-purple">【方向】:{{dataList.direction}}</div></el-col>
      </el-row>
      <hr>
          <div>【题干】:
            <div class="questionStyle" v-html="dataList.question"></div>
            <div v-if="dataList.questionType === '1'">
              <div>单选题 选项: (以下选中的选项为正确答案)</div>
              <el-radio-group :value="1">
                <el-radio
                  style="display: block; padding: 8px 0"
                  v-for="item in dataList.options"
                  :key="item.id"
                  :label="item.isRight"
                >
                  {{item.title}}
                </el-radio>
              </el-radio-group>
            </div>
            <div v-if="dataList.questionType === '2'">
              <div>多选题 选项: (以下选中的选项为正确答案)</div>
              <el-checkbox-group :value="[1]">
                <el-checkbox
                  style="display: block; padding: 8px 0"
                  v-for="item in dataList.options"
                  :key="item.id"
                  :label="item.isRight"
                >
                {{item.title}}
                </el-checkbox>
              </el-checkbox-group>
            </div>
          </div>
        <hr>
          <span>【参考答案】:</span>
          <el-button type="danger" @click="openVideoPlayer">视频答案预览</el-button>
          <div v-if="videoURL">
            <meta name="referrer" content="never">
            <video
              ref="video"
              class="videobox"
              autoplay="autoplay"
              controls="controls"
              :src="dataList.videoURL"
            ></video>
          </div>
        <hr>
          <span>【答案解析】:</span>
          <div style="display: inline-block;" v-html="dataList.answer"></div>
      <hr>
        <span>【题目备注】:{{dataList.remarks}}</span>
      <el-row type="flex" justify="end"  class="ShutDownButton">
        <el-col :span="2">
          <el-button type="primary" @click="close">关闭</el-button>
        </el-col>
      </el-row>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { detail } from '../../api/hmmm/questions'
export default {
  props: {
    showDialog: {
      type: Boolean,
      default: false
    },
    currentNodeId: {
      type: Number,
      default: null
    }
  },
  data () {
    return {
      // 数据列表
      dataList: {
        id: null, // 编号
        questionType: '', // 题型
        number: '', // 试题编号
        difficulty: '', // 难度
        tags: '', // 标签
        subjectName: '', // 学科
        directoryName: '', // 目录
        direction: '', // 方向
        question: '', // 题干
        options: [], // 选项
        videoURL: '', // 解析视频
        answer: '', // 答案解析
        remarks: ''// 题目备注
      },
      videoURL: false
    }
  },
  methods: {
    // 打开视频播放器
    openVideoPlayer (video) {
      this.dataList.videoURL = video
      this.videoURL = true
    },
    close () {
      // 关闭弹层
      this.$emit('update:showDialog', false)
      // this.$refs.clearData.resetFields()
    },
    // 获取基础题库详情
    async getFoundationDetails () {
      const { data } = await detail(this.currentNodeId)
      this.dataList = data
      console.log(this.dataList)
    }
  }
}
</script>

<style lang='less' scoped>
 .grid-content {
  padding: 10px 0;
 }
 .ShutDownButton {
  padding: 10px 20px 20px;
 }
 .questionStyle{
  color: blue;
 }
  .videobox {
  width: 350px;
  height: 200px;
 }
</style>
